﻿<?php

echo $picture 		= $this->formFile('images');
$linkUploadify = $this->cmsUrl(array(
										'module' => 'admin',
										'controller' => 'admin-products',
										'action' => 'uploadify'
										));
$linkDelete = $this->cmsUrl(array(
										'module' => 'admin',
										'controller' => 'admin-products',
										'action' => 'remove-pic',
										'type' => 'uploadify'
										));	
$config = new Zendvn_Controller_Config(array('module' => $this->arrParam['module'],
													 	  'fileConfig'=>'product-category.ini'));
$imageConfig = $config->getConfig('item');	

$select = $this->formSelect('imagecolor',null,null,$imageConfig['color']);




?>
<style>
	.image{
		margin-top: 10px;
		float: left;
		border: 1px solid #ccc;
		border-radius: 10px;
		padding: 10px 10px 10px;
		position: relative;
		margin-right: 10px;
	}
	
	.image .choose-color{
		position: absolute;
		top: 10px;
		left: 10px;
		min-width: 75px;	
	}
	
	.image .img_upload{
		padding: 5px;
		background: #ddd;
		margin-top: 25px;
	}
	.image .img_upload:hover{
		opacity: 0.6;	
	}
	.image .btn_delete{
		position: absolute;
		top: 10px;
		right: 5px;
		cursor: pointer;
	}
</style>	
<div id="getSelect" style="display: none">
	<?php echo $select;?>
</div>
<script type="text/javascript">
$(document).ready(function() {
	$("#images").uploadify({
		'uploader'  		: '<?php echo SCRIPTS_URL .'/uploadify/uploadify.swf';?>',
      	'script'    		: '<?php echo $linkUploadify; ?>',
      	'cancelImg' 		: '<?php echo SCRIPTS_URL."/uploadify/cancel.png"; ?>',                                                 
       	'multi'     		: true,         
       	'auto'      		: true,
       	'sizeLimit'			: '40000000000', 
       	'queueSizeLimit'	: '10',
       	'fileExt'     		: '*.jpg;*.gif;*.png;*.jpeg',
       	'fileDesc'    		: 'Picture Files',
       	'fileDataName' 		: 'picture',
       	'onComplete'  		: function(event, ID, fileObj, response, data) {
       		if(response == 'error'){
				alert("File size is greater than allowed or not properly formatted.",'Error');
        	}else{
            	var select = $("#getSelect").html();
            	
				var result ="<div id='"+response+"' class='image'>"
				+"<img class='img_upload' height='"+150+"' width='"+150+"' src='<?php echo $imageConfig['thumbUrl2'] . '/'; ?>"+response+"' />"
				+"<input type='hidden' name='images_hidden["+response+"]' value='"+response+"' />"
				+"<img class='btn_delete' src='<?php echo SCRIPTS_URL."/uploadify/cancel.png"; ?>' onClick='deleteImage(this)' />"
				+ select
				+"</div>";
	          	$('#result').append(result);
        	} 
        },                             
    });

    $("select[name='imagecolor']").live('change',function(){
        var parent = $(this).parent();
        var id = parent.attr("id");
        var html = "<input type='hidden' name='images_hidden_color["+id+"]' value='"+$(this).val()+"' />";
        parent.append(html);
        
    });
    
});
</script>


<div id="result">
<script>
function deleteImage(a){
	var id = $(a).parent().attr('id');
	$(a).prev().remove();
	$.post('<?php echo $linkDelete; ?>' + '/file/' + id, function(data){
		 			$(a).parent().fadeOut();
				})
}
</script>
</div>